package com.hex.ds.hdtp.core.inf.script.test.po;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.script.test.po
 * @ClassName ScriptDataTestTaskPo
 * @Description: 脚本带数据测试任务
 * @Author: wz.li
 * @Date 2023/8/1 12:01
 * @Version v2.0.2
 **/
@Data
@Accessors(chain = true)
@TableName(value = "tm_script_data_test_task")
public class ScriptDataTestTaskPo implements Serializable {

    @TableId(value = "pk_id", type = IdType.ASSIGN_UUID)
    private String pkId;

    @TableField(value = "task_name")
    private String taskName;

    @TableField(value = "is_data_alignment")
    private String isDataAlignment;

    @TableField(value = "data_sync_type")
    private String dataSyncType;

    @TableField(value = "data_sync_start_time")
    private String dataSyncStartTime;

    @TableField(value = "data_sync_end_time")
    private String dataSyncEndTime;

    @TableField(value = "status")
    private String status;

    @TableField(value = "test_total")
    private Integer testTotal;

    @TableField(value = "test_success_count")
    private Integer testSuccessCount;

    @TableField(value = "test_fail_count")
    private Integer testFailCount;

    @TableField(value = "start_time")
    private String startTime;

    @TableField(value = "end_time")
    private String endTime;

    @TableField(value = "crt_user", fill = FieldFill.INSERT)
    private String crtUser;

    @TableField(value = "crt_user_name", fill = FieldFill.INSERT)
    private String crtUserName;

    @TableField(value = "crt_ts", fill = FieldFill.INSERT)
    private String crtTs;

    @TableField(value = "up_user", fill = FieldFill.INSERT_UPDATE)
    private String upUser;

    @TableField(value = "up_user_name", fill = FieldFill.INSERT_UPDATE)
    private String upUserName;

    @TableField(value = "up_ts", fill = FieldFill.INSERT_UPDATE)
    private String upTs;

    public List<DateTime> getBizDateList() {
        if (dataSyncType.equals("TODAY")) {
            return Arrays.asList(DateUtil.date());
        } else if (dataSyncType.equals("YESTERDAY")) {
            return Arrays.asList(DateUtil.yesterday());
        } else if (dataSyncType.equals("DAY_LAST_MONTH")) {
            return Arrays.asList( DateUtil.endOfMonth(DateUtil.date()));
        } else {
            return DateUtil.rangeToList(DateUtil.parse(dataSyncStartTime), DateUtil.parse(dataSyncEndTime), DateField.DAY_OF_YEAR);
        }
    }
}
